package com.lc.sell.controller;

import com.lc.sell.service.MerchantService;
import com.lc.sell.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "登录控制器")
@Controller
public class LoginController {

    @Autowired
    private MerchantService merchantService;

    @GetMapping("login")
    @ApiOperation(value = "跳转到登录页")
    public String toLogin(){
        return "login";
    }

    @GetMapping("logout")
    public ResultVo logOut(HttpServletRequest request){
        request.getSession().setAttribute("mid",null);
        return ResultVo.ok("退出成功!");
    }

    @PostMapping("admin/login")
    @ApiOperation(value = "登录")
    @ResponseBody
    public ResultVo login(HttpServletRequest request,String username,String password){
        return merchantService.toLogin(request, username, password);
    }
}
